package com.luania.todolist2.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.luania.todolist2.Adapter.IconAdapter;
import com.luania.todolist2.R;
import com.luania.todolist2.Model.ImageModel;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by tyz1201 on 2016/3/30.
 */
public class ListsActivity extends AppCompatActivity {

    List<ImageModel> images = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lists_main);

        Toolbar toolbar2 = (Toolbar) findViewById(R.id.toolbar2);
        toolbar2.setTitle("选择Icon");
        toolbar2.setTitleTextColor(getResources().getColor(R.color.colorWhite));
        setSupportActionBar(toolbar2);

        ListView lv_icon = (ListView) findViewById(R.id.lv_icon);
        initImages();

        IconAdapter iconAdapter = new IconAdapter(images, ListsActivity.this);
        lv_icon.setAdapter(iconAdapter);

        lv_icon.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int IconId = images.get(position).getImageId();

                Intent data = new Intent();
                data.putExtra("IconId", IconId);
                setResult(RESULT_OK, data);
                finish();
            }
        });


    }

    void initImages() {
        ImageModel appointments = new ImageModel(R.mipmap.appointments, "appointments");
        ImageModel birthdays = new ImageModel(R.mipmap.birthdays, "birthdays");
        ImageModel chores = new ImageModel(R.mipmap.chores, "chores");
        ImageModel drinks = new ImageModel(R.mipmap.drinks, "drinks");
        ImageModel folder = new ImageModel(R.mipmap.folder, "folder");
        ImageModel groceries = new ImageModel(R.mipmap.groceries, "groceries");
        ImageModel inbox = new ImageModel(R.mipmap.inbox, "inbox");
        ImageModel photos = new ImageModel(R.mipmap.photos, "photos");
        ImageModel trips = new ImageModel(R.mipmap.trips, "trips");

        images.add(appointments);
        images.add(birthdays);
        images.add(chores);
        images.add(drinks);
        images.add(folder);
        images.add(groceries);
        images.add(inbox);
        images.add(photos);
        images.add(trips);


    }

}
